package view;

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

import javazoom.jl.player.*;
import javazoom.jl.decoder.*;

public class Audio {
	private Player player;
	private String fileName;

	public Audio(String fileName) {
		this.fileName = fileName;
	}

	public void stop() {
		if (player != null)
			player.close();
	}

	public void play() throws IOException, JavaLayerException {
		BufferedInputStream bis = new BufferedInputStream(new FileInputStream(
				fileName));
		player = new Player(bis);

		new Thread(new Runnable() {

			@Override
			public void run() {
				// TODO Auto-generated method stub
				try {
					player.play();
				} catch (JavaLayerException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}).start();
	}
	public static void main(String[] args) {
		try {
			new Audio("sounds/win.mp3").play();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (JavaLayerException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
